package com.chinaisafe.user.controller;

import com.chinaisafe.base.common.validated.UpdateGroup;
import com.chinaisafe.user.biz.SysTenantAppBiz;
import com.chinaisafe.user.biz.SysTenantBiz;
import com.chinaisafe.user.entity.SysMenu;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.vo.Answer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.chinaisafe.user.vo.request.SysTenantAppReqVO;
import com.chinaisafe.user.vo.response.SysTenantAppRespVO;
import org.springframework.validation.annotation.Validated;
import com.chinaisafe.user.service.SysTenantAppService;
import org.springframework.web.bind.annotation.RestController;
import com.chinaisafe.base.common.validated.AddGroup;
/**
 * SysTenantAppController
 * Description：租户和应用接口层
 *
 * @author tby
 * @date  2024-07-12 10:04:27
 */
@RestController
@RequestMapping("/sysTenantApp")
@Tag(name = "系统级应用管理", description = "系统级应用管理")
public class SysTenantAppController {

    @Autowired
    private SysTenantAppService sysTenantAppService;

    @Resource
    private SysTenantAppBiz sysTenantAppBiz;

    @GetMapping("/pageList")
    @Operation(summary = "获取系统级应用分页列表", description = "获取系统级应用分页列表")
    public Answer<IPage<SysTenantAppRespVO>> pageList(SysTenantAppReqVO sysTenantAppReqVO) {
        IPage<SysTenantAppRespVO> pageList = sysTenantAppService.getPageList(sysTenantAppReqVO);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping("shelfSwitch")
    @Operation(summary = "上架/下架", description = "参数放在?后面")
    @OperationLog(title = "上架/下架", businessType = BusinessTypeEnum.UPDATE)
    public Answer<Void> shelfSwitch(Long sysAppId) {
        sysTenantAppBiz.shelfSwitch(sysAppId);
        return Answer.success("保存成功");
    }

    @PostMapping("rename")
    @Operation(summary = "修改别名", description = "修改别名")
    @OperationLog(title = "修改别名", businessType = BusinessTypeEnum.UPDATE)
    public Answer<Void> rename(@Validated(UpdateGroup.class)@RequestBody SysTenantAppReqVO sysTenantAppReqVO) {
        sysTenantAppBiz.rename(sysTenantAppReqVO);
        return Answer.success("保存成功");
    }



    @GetMapping("/{sysTenantAppId}")
    @Operation(summary = "根据id获取租户的应用", description = "根据id获取租户的应用")
    public Answer<SysTenantAppRespVO> getDetailById(@PathVariable Long sysTenantAppId) {
        SysTenantAppRespVO sysTenantAppRespVO = sysTenantAppService.getDetailById(sysTenantAppId);
        return Answer.success("获取成功", sysTenantAppRespVO);
    }


}

